class UserRank < ActiveRecord::Base
  acts_as_paranoid
  
  has_many :users
  
  validates_presence_of :name, :int_min, :int_max, :discount
  validates_numericality_of :int_min, :greater_than_or_equal_to => 0
  validates_numericality_of :int_max, :greater_than_or_equal_to => 0
  validates_numericality_of :discount, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100
  
  HUMANIZED_ATTRIBUTES_ORDERS = {:name => 1,
                                 :int_min => 2,
                                 :int_max => 3,
                                 :discount => 4
  }

  def validate
    
  end
  
  # 导入默认用户级别
  #【参数】
  #【返回值】
  #【注意】
  #【作者】by ljl 2012.02.14
  def self.import_data
    user_rank = UserRank.new({:name => "普通会员", :int_min => 0, :int_max => 500, :discount => 100})
    user_rank.save(false)
    user_rank = UserRank.new({:name => "高级会员", :int_min => 500, :int_max => 3000, :discount => 90})
    user_rank.save(false)
    user_rank = UserRank.new({:name => "VIP会员", :int_min => 3000, :int_max => 50000, :discount => 80})
    user_rank.save(false)
  end
  
  
  def self.options_for_select
    options = []
    blocks = UserRank.all(:select => "id, name")
    if blocks.present?
      options = blocks.collect{ |b| [b.name.to_s, b.id] }
    end
    options.insert(0, ["", ""])
    return options
  end
  
end
